package com.yu8home.mq.rabbit.ttl;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class RabbitConfig3 {

    @Bean
    CustomExchange orderDelayedDirect() {
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", "direct");
        // args.put("x-delayed", 10 * 1000);// 无效
        return new CustomExchange(QueueEnum.ORDER_DELAYED.getExchange(), "x-delayed-message", true, false, args);
    }

    @Bean
    public Queue orderDelayedQueue() {
        return new Queue(QueueEnum.ORDER_DELAYED.getName());
    }

    @Bean
    public Binding orderPluginBinding(CustomExchange orderDelayedDirect, Queue orderDelayedQueue) {
        return BindingBuilder.bind(orderDelayedQueue).to(orderDelayedDirect).with(QueueEnum.ORDER_DELAYED.getRouteKey()).noargs();
    }

}
